package ace.cmp.util;

import java.util.ArrayList;
import java.util.Collections;
import lombok.SneakyThrows;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * @author caspar
 * @date 2024/7/10 14:10
 */
public final class MultiValueMapUtils {

  @SneakyThrows
  public static MultiValueMap<String, String> describe(Object object) {
    return BeanUtils.describe(object).entrySet().stream()
        .collect(
            LinkedMultiValueMap::new,
            (m, entry) -> {
              String id = entry.getKey();
              String value = entry.getValue();
              m.put(id, new ArrayList<>(Collections.singletonList(value)));
            },
            LinkedMultiValueMap::putAll);
  }
}
